import router from '@system.router';
import dataStorage from '@ohos.data.storage';
export default {
    data: {
        title: 'World',
    },
    onInit(){
        let store = dataStorage.getStorageSync('/data/data/com.example.imitationtaobao/files/mystore');
        store.get('flag', 0).then((value) => {
            this.$app.$def.globalData.flag = value;
            console.log("抓取成功，值为"+value);
        }).catch((err) => {
            console.info("Get the value of startup failed with err: " + err)
        });
        console.log('值1:'+this.$app.$def.globalData.flag)
    },
    onShow(){
        let store = dataStorage.getStorageSync('/data/data/com.example.imitationtaobao/files/mystore');
        store.get('flag', 0).then((value) => {
            this.$app.$def.globalData.flag = value;
            console.log("抓取成功，值为"+value);
        }).catch((err) => {
            console.info("Get the value of startup failed with err: " + err)
        });
        console.log('值1:'+this.$app.$def.globalData.flag)

        if(this.$app.$def.globalData.flag==0){
            console.log("1:"+this.$app.$def.globalData.flag)
            router.push({
                uri:"pages/yindao/yindao",
            })
        }else{
            console.log('2:'+this.$app.$def.globalData.flag);
            router.push({
                uri:"pages/qidong/qidong",
            })
        }
    },
    onActive(){
        let store = dataStorage.getStorageSync('/data/data/com.example.imitationtaobao/files/mystore');
        store.get('flag', 0).then((value) => {
            this.$app.$def.globalData.flag = value;
            console.log("抓取成功，值为"+value);
        }).catch((err) => {
            console.info("Get the value of startup failed with err: " + err)
        });
        console.log('值1:'+this.$app.$def.globalData.flag)

        if(this.$app.$def.globalData.flag==0){
            console.log("1:"+this.$app.$def.globalData.flag)
            router.push({
                uri:"pages/yindao/yindao",
            })
        }else{
            console.log('2:'+this.$app.$def.globalData.flag);
            router.push({
                uri:"pages/qidong/qidong",
            })
        }
    }
}
